home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / grafxtp.exe / GRAPHICS.DOC < prev    next >
Text File  |  1991-04-25  |  9KB  |  185 lines

  1. Unit Graphics;
  2.  
  3. { Turbo Pascal 6.0 unit for graphics handling.  Provides a generic graphic
  4.   container object and procedures to manipulate the object.  All of the pro-
  5.   cedures are written to deal with a rectangular area of the screen which
  6.   will be, or will contain, a graphic image.  Currently, the actual image
  7.   generation is up to the programmer - Drawing tools may be included at a
  8.   later date.  Of course, you MUST be in graphics mode before instantiating
  9.   an object of type Graphic.
  10.  
  11.   Written By Jim Fralix.  I can be reached on CompuServe (ID# 72317,3614) or
  12.   in writing at :  Jim Fralix
  13.                    415 Parkdale Dr. #5B
  14.                    Charleston, SC  29414.
  15.   This version is public domain, or FreeWare, with the anticipation of future
  16.   releases with more features that will eventually be marketed as Shareware.
  17.   Please feel free to copy, distribute, and use this unit.  I only ask that
  18.   you do not modify the documentation or code when distributing these files to
  19.   others.  I will accept no liability for the use or misuse of this material.
  20.   If your keyboard breaks in half, you own both halves!
  21.  
  22.   The commented Interface portion of the code (shown below) will serve as the
  23.   documentation and reference material.  The source code for this unit will
  24.   NOT be published unless this evolves into shareware.  Registered users of a
  25.   future shareware version WILL be provided with the source code.  I made all
  26.   of the object procedures Virtual so that they may be extended for any descen-
  27.   dant type objects.
  28.  
  29.   This is version 1.00 as it is the first version I have distributed for public
  30.   use.  This unit was written for a specific project and does everything I
  31.   needed it to do, so upgrades and bug fixes will depend largely on user feed-
  32.   back.  I am distributing this version free, hoping that I can get a lot of
  33.   input from the users.  Responses (or lack thereof) will determine the future
  34.   of this unit, so please let me know what you think!
  35. }
  36.  
  37. Interface
  38.  
  39. Uses Graph;
  40.  
  41.    Const
  42.  
  43.       { Directions }
  44.  
  45.       Up : Byte = 1;  Right : Byte = 2;  Down : Byte = 3;  Left : Byte = 4;
  46.  
  47.       { Put Types }
  48.  
  49.       CopyPut = 0;    XOrPut = 1;  OrPut = 2;   AndPut = 3;     NotPut = 4;
  50.  
  51.    Type
  52.  
  53.       Coordinates = Record   { Used in Graphic Object }
  54.          X,
  55.          Y  : Integer;
  56.       End;
  57.  
  58.       Graphic = Object  { This is the object type you will be using! }
  59.  
  60.          OK : Boolean;  { Set by procs marked with (**) }
  61.  
  62.    (**)  Constructor Init (x1,y1,x2,y2 : Word);
  63.             { Allocates memory for screen image rectangle bounded by x1,y1
  64.               at the top left corner and x2,y2 at the bottom right corner.
  65.               Sets OK to false if unable to allocate the memory needed.
  66.               Max image size in 640 x 350 x 16 color mode is a little more
  67.               than half a screen.  The amount of the screen you can "grab"
  68.               will vary according to the graphics mode, but the image must
  69.               require <= 64K. Can be called by the New method. }
  70.  
  71.    (**)  Procedure Relocate (X, Y : Integer);
  72.             { Makes X,Y the new top left corner of the graphic.  This pro-
  73.               cedure does not display the image at the new position, but
  74.               sets other object parameters as required.  If the new position
  75.               would "push" any of the image off the screen, the position is
  76.               adjusted to be as close as possible to the position requested
  77.               while keeping the entire image on screen. }
  78.          Procedure Get;
  79.             { Takes a "snapshot" of the image bounded by currently defined
  80.               rectangle }
  81.  
  82.    (**)  Procedure Put (PutType : Word);
  83.             { Places the image on screen in the currently defined position.
  84.               PutType determines how the image is shown.  The following
  85.               descriptions are meant to give you a feel for what effect the
  86.               different types of puts will have, but some experimenting of
  87.               your own is in order as these are very general descriptions.
  88.               CopyPut makes an exact copy of the image, but any existing
  89.               image "under" the new image is obliterated.  XOrPut will pre-
  90.               serve the underlying image, and will restore to original if
  91.               called twice in a row. OrPut will put an "opaque" image that
  92.               will allow both images to be seen (some color distortions may
  93.               occur where the images overlap).  NotPut does a reverse image
  94.               CopyPut. }
  95.  
  96.    (**)  Procedure CopyTo (X, Y : Integer; PutType : Byte);
  97.             { Copies image to X,Y and puts image with PutType.  Makes X,Y
  98.               the new top left corner of rectangle }
  99.  
  100.    (**)  Procedure MoveTo (X, Y : Integer; PutType : Byte);
  101.             { Does an XOrPut of image, relocates to X,Y, and puts image with
  102.               PutType.  Makes X,Y the new top left corner of rectangle }
  103.  
  104.    (**)  Procedure DragIt (Direction, Amount : Byte);
  105.             { Temporarily puts image on screen offset "amount" positions in
  106.               "Direction" from current rectangle or last DragIt position.
  107.               Once a drag has been started, the drag must be ended with the
  108.               EndDrag procedure below. Each call to DragIt updates the
  109.               graphic rectangle location - to restore back to location before
  110.               the DragIt call(s) were made, call AbortDrag  procedure. }
  111.  
  112.          Procedure EndDrag;
  113.             { Use to end DragIt - erases last image put on screen }
  114.  
  115.          Procedure AbortDrag;
  116.             { Use to abort drag and restore original rectangle. }
  117.  
  118.          Procedure Write (Var SaveFile : File);
  119.             { Writes graphic image to a file. The file should be untyped and
  120.               opened with a record size of 1 (see the rewrite procedure docs
  121.               for more details).  Writes the size, screen location coordi-
  122.               nates, and image info to the file.  Each write takes 10 bytes
  123.               plus the size of the image.  Multiple images may be written to
  124.               the same file, but must be read sequentially. }
  125.  
  126.          Procedure Read (Var ReadFile : File);
  127.             { Reads a graphic image from a file.  The file should be untyped
  128.               and opened with a record size of 1.  Reads the size, screen
  129.               location coordinates, and image info.  If necessary, re-allo-
  130.               cates memory for the image. }
  131.  
  132.          Destructor Done;
  133.             { Call when finished using an image. De-allocates memory for the
  134.               image, can be called by dispose method. }
  135.  
  136.          Private
  137.  
  138.          ----------------end-of-author's-documentation---------------
  139.  
  140.                          Software Library Information:
  141.  
  142.                     This disk copy provided as a service of
  143.  
  144.                            Public (software) Library
  145.  
  146.          We are not the authors of this program, nor are we associated
  147.          with the author in any way other than as a distributor of the
  148.          program in accordance with the author's terms of distribution.
  149.  
  150.          Please direct shareware payments and specific questions about
  151.          this program to the author of the program, whose name appears
  152.          elsewhere in  this documentation. If you have trouble getting
  153.          in touch with the author,  we will do whatever we can to help
  154.          you with your questions. All programs have been tested and do
  155.          run.  To report problems,  please use the form that is in the
  156.          file PROBLEM.DOC on many of our disks or in other written for-
  157.          mat with screen printouts, if possible.  PsL cannot debug pro-
  158.          programs over the telephone, though we can answer questions.
  159.  
  160.          Disks in the PsL are updated  monthly,  so if you did not get
  161.          this disk directly from the PsL, you should be aware that the
  162.          files in this set may no longer be the current versions. Also,
  163.          if you got this disk from another vendor and are having prob-
  164.          lems,  be aware that  some fi